﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LiteBlog.Common.Components
{
    public class DateTimeHelper
    {
        private static string _timezone = string.Empty;

        public static void SetTimezone(string timezone)
        {
            _timezone = timezone;
        }

        public static DateTime Now
        {
            get
            {
                if (string.IsNullOrEmpty(_timezone))
                    throw new NullReferenceException("Timezone not set");

                var tzi = TimeZoneInfo.FindSystemTimeZoneById(_timezone);
                return TimeZoneInfo.ConvertTime(DateTime.Now, tzi);
            }
        }

        public static TimeSpan TimezoneOffset
        {
            get
            {
                var tzi = TimeZoneInfo.FindSystemTimeZoneById(_timezone);
                return tzi.BaseUtcOffset;
            }
        }
    }
}
